home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / chit / chit_src.lzh / STR.ASM < prev    next >
Assembly Source File  |  1991-05-23  |  10KB  |  346 lines

  1. ;===============================================
  2. ;        str.asm        91-05-23    
  3. ;===============================================
  4.  
  5.         .386p
  6.  
  7. CODE        segment    public dword use32
  8. CODE        ends
  9. DATA        segment    public dword use32
  10. DATA        ends
  11. BSS        segment    public dword use32
  12. BSS        ends
  13.  
  14. DGROUP        group    DATA,BSS
  15. ;===============================================================
  16. CODE        segment
  17.         assume    cs:CODE,gs:DGROUP
  18.  
  19.         public    disp_str
  20.         public    disp_str2
  21.         public    put_ank
  22.         public    color_set
  23. ;---------------------------------------------------------------
  24. disp_str    proc    near
  25. ;-----------------------------------------------
  26. ;in:    ds:esi    *string                
  27. ;    dx    locate(dl=x,dh=y)        
  28. ;    bl    color(high=back, low=font)    
  29. ;out:    ds:esi    next *string            
  30. ;    edi    next *vram (offset)        
  31. ;break:    nothing                    
  32. ;-----------------------------------------------
  33.         push    eax
  34.         push    ebx
  35.         push    ecx
  36.         push    edx
  37.         push    ebp
  38.         push    es
  39.  
  40.         mov    ax,120h
  41.         mov    es,ax                ;VRAM sel
  42.  
  43.         movzx    edi,dh
  44.         shl    edi,13                ;edi=y*512*16
  45.         and    edx,000000ffh
  46.         lea    edi,[edi+edx*4]            ;edi=*vram
  47.  
  48.         movzx    edx,bl
  49.         shr    edx,4
  50.         mov    edx,gs:[color_ptn+edx*4]    ;back color
  51.         and    ebx,0000000fh
  52.         mov    ebx,gs:[color_ptn+ebx*4]    ;font color
  53.         mov    gs:[font_color],ebx
  54.         mov    gs:[back_color],edx
  55.  
  56.         align    4
  57. disp_str_lp:    movzx    eax,byte ptr ds:[esi]
  58.         inc    esi
  59.         and    al,al                ;al=0?
  60.         je    disp_str_e            ;yes
  61.  
  62.         mov    bl,gs:[sjis_tbl+eax]
  63.         and    bl,SJIS1?            ;sjis 1st byte?
  64.         je    disp_ank            ;no
  65.         movzx    ebx,byte ptr ds:[esi]
  66.         mov    bh,gs:[sjis_tbl+ebx]
  67.         and    bh,SJIS2?            ;sjis 2nd byte?
  68.         je    disp_ank            ;no
  69.         mov    bh,al                ;bx=sjis code
  70.         inc    esi
  71.  
  72.         add    bh,bh                ;sjis to jis
  73.         cmp    bl,80h
  74.         adc    bx,1f61h
  75.         add    bl,7fh
  76.         jb    short knf1
  77.         add    bl,0a2h
  78. knf1:        and    bh,7fh                ;bx=jis code
  79.  
  80.         push    esi
  81.         push    ds
  82.  
  83.         mov    ax,0100h
  84.         mov    dx,1010h
  85.         call    fword ptr fs:[00a0h]        ;ds:esi=*font
  86.  
  87.         mov    ebx,gs:[font_color]
  88.         mov    ebp,gs:[back_color]
  89.         mov    ecx,16
  90.  
  91.         align    4
  92. disp_kanji_lp:    movzx    eax,byte ptr ds:[esi]
  93.         inc    esi
  94.         mov    eax,gs:[font_ptn+eax*4]
  95.         mov    edx,eax
  96.         not    edx
  97.         and    eax,ebx
  98.         and    edx,ebp
  99.         or    eax,edx
  100.         mov    es:[edi],eax
  101.  
  102.         movzx    eax,byte ptr ds:[esi]
  103.         inc    esi
  104.         mov    eax,gs:[font_ptn+eax*4]
  105.         mov    edx,eax
  106.         not    edx
  107.         and    eax,ebx
  108.         and    edx,ebp
  109.         or    eax,edx
  110.         mov    es:[edi+4],eax
  111.  
  112.         add    edi,512                ;next line
  113.         loop    disp_kanji_lp
  114.  
  115.         pop    ds
  116.         pop    esi
  117.         sub    edi,512*16-8            ;next *vram
  118.         jmp    disp_str_lp
  119.  
  120. disp_ank:    call    put_ank
  121.         jmp    disp_str_lp
  122.  
  123. disp_str_e:
  124.         pop    es
  125.         pop    ebp
  126.         pop    edx
  127.         pop    ecx
  128.         pop    ebx
  129.         pop    eax
  130.         ret
  131. disp_str    endp
  132. ;---------------------------------------------------------------
  133. disp_str2    proc    near
  134. ;-----------------------------------------------
  135. ;in:    ds:esi    *string                
  136. ;    dx    locate(dl=x,dh=y)        
  137. ;    ecx    length                
  138. ;    bl    color(high=back, low=font)    
  139. ;out:    ds:esi    next *string            
  140. ;    edi    next *vram (offset)        
  141. ;break:    nothing                    
  142. ;-----------------------------------------------
  143.         push    eax
  144.         push    ecx
  145.         push    es
  146.  
  147.         mov    eax,esi            ;keep *string
  148.         call    disp_str
  149.  
  150.         xchg    eax,esi
  151.         sub    eax,esi
  152.         dec    eax            ;esi=string length
  153.         sub    ecx,eax
  154.         jbe    short fill_sp_e
  155.  
  156.         mov    ax,120h
  157.         mov    es,ax            ;VRAM sel
  158.  
  159.         mov    al,20h            ;space
  160. fill_sp_lp:    call    put_ank
  161.         loop    fill_sp_lp
  162. fill_sp_e:
  163.         pop    es
  164.         pop    ecx
  165.         pop    eax
  166.         ret
  167. disp_str2    endp
  168. ;---------------------------------------------------------------
  169. put_ank        proc    near
  170. ;-----------------------------------------------
  171. ;in:    al        ank code        
  172. ;    es:edi        *vram            
  173. ;    gs:[font_color]    font_color        
  174. ;    gs:[back_color]    back_color        
  175. ;out:    edi        next *vram (offset)    
  176. ;break:    nothing                    
  177. ;-----------------------------------------------
  178.         pushad
  179.         push    ds
  180.  
  181.         movzx    esi,al
  182.         add    esi,esi
  183.         lea    esi,[3d800h+esi*8]        ;esi=al*16+3d800h
  184.  
  185.         mov    ax,138h                ;font rom sel
  186.         mov    ds,ax                ;ds:esi=*font
  187.  
  188.         mov    ebx,gs:[font_color]
  189.         mov    ebp,gs:[back_color]
  190.         mov    ecx,16
  191.  
  192.         align    4
  193. put_ank_lp:    movzx    eax,byte ptr ds:[esi]
  194.         inc    esi
  195.  
  196.         mov    eax,gs:[font_ptn+eax*4]
  197.         mov    edx,eax
  198.         not    edx
  199.         and    eax,ebx
  200.         and    edx,ebp
  201.         or    eax,edx
  202.  
  203.         mov    es:[edi],eax
  204.         add    edi,512                ;next line
  205.  
  206.         loop    put_ank_lp
  207.  
  208.         pop    ds
  209.         popad
  210.         add    edi,4                ;next *vram
  211.         ret
  212. put_ank        endp
  213. ;---------------------------------------------------------------
  214. color_set    proc    near
  215. ;-----------------------------------------------
  216. ;in:    bl        color (back:font)    
  217. ;out:    gs:[font_color]    font_color        
  218. ;    gs:[back_color]    back_color        
  219. ;break:    nothing                    
  220. ;-----------------------------------------------
  221.         push    ebx
  222.         push    edx
  223.  
  224.         movzx    edx,bl
  225.         shr    edx,4
  226.         mov    edx,gs:[color_ptn+edx*4]    ;back color
  227.         and    ebx,0000000fh
  228.         mov    ebx,gs:[color_ptn+ebx*4]    ;font color
  229.         mov    gs:[font_color],ebx
  230.         mov    gs:[back_color],edx
  231.  
  232.         pop    edx
  233.         pop    ebx
  234.         ret
  235. color_set    endp
  236. ;---------------------------------------------------------------
  237. CODE        ends
  238. ;===============================================================
  239. DATA        segment
  240. ;-----------------------------------------------
  241. ;    16色VRAMビットパタ-ン            
  242. ;-----------------------------------------------
  243. color_ptn    dd    000000000h,011111111h,022222222h,033333333h
  244.         dd    044444444h,055555555h,066666666h,077777777h
  245.         dd    088888888h,099999999h,0AAAAAAAAh,0BBBBBBBBh
  246.         dd    0CCCCCCCCh,0DDDDDDDDh,0EEEEEEEEh,0FFFFFFFFh
  247.  
  248. font_ptn    dd    000000000h,0F0000000h,00F000000h,0FF000000h
  249.         dd    000F00000h,0F0F00000h,00FF00000h,0FFF00000h
  250.         dd    0000F0000h,0F00F0000h,00F0F0000h,0FF0F0000h
  251.         dd    000FF0000h,0F0FF0000h,00FFF0000h,0FFFF0000h
  252.         dd    00000F000h,0F000F000h,00F00F000h,0FF00F000h
  253.         dd    000F0F000h,0F0F0F000h,00FF0F000h,0FFF0F000h
  254.         dd    0000FF000h,0F00FF000h,00F0FF000h,0FF0FF000h
  255.         dd    000FFF000h,0F0FFF000h,00FFFF000h,0FFFFF000h
  256.         dd    000000F00h,0F0000F00h,00F000F00h,0FF000F00h
  257.         dd    000F00F00h,0F0F00F00h,00FF00F00h,0FFF00F00h
  258.         dd    0000F0F00h,0F00F0F00h,00F0F0F00h,0FF0F0F00h
  259.         dd    000FF0F00h,0F0FF0F00h,00FFF0F00h,0FFFF0F00h
  260.         dd    00000FF00h,0F000FF00h,00F00FF00h,0FF00FF00h
  261.         dd    000F0FF00h,0F0F0FF00h,00FF0FF00h,0FFF0FF00h
  262.         dd    0000FFF00h,0F00FFF00h,00F0FFF00h,0FF0FFF00h
  263.         dd    000FFFF00h,0F0FFFF00h,00FFFFF00h,0FFFFFF00h
  264.         dd    0000000F0h,0F00000F0h,00F0000F0h,0FF0000F0h
  265.         dd    000F000F0h,0F0F000F0h,00FF000F0h,0FFF000F0h
  266.         dd    0000F00F0h,0F00F00F0h,00F0F00F0h,0FF0F00F0h
  267.         dd    000FF00F0h,0F0FF00F0h,00FFF00F0h,0FFFF00F0h
  268.         dd    00000F0F0h,0F000F0F0h,00F00F0F0h,0FF00F0F0h
  269.         dd    000F0F0F0h,0F0F0F0F0h,00FF0F0F0h,0FFF0F0F0h
  270.         dd    0000FF0F0h,0F00FF0F0h,00F0FF0F0h,0FF0FF0F0h
  271.         dd    000FFF0F0h,0F0FFF0F0h,00FFFF0F0h,0FFFFF0F0h
  272.         dd    000000FF0h,0F0000FF0h,00F000FF0h,0FF000FF0h
  273.         dd    000F00FF0h,0F0F00FF0h,00FF00FF0h,0FFF00FF0h
  274.         dd    0000F0FF0h,0F00F0FF0h,00F0F0FF0h,0FF0F0FF0h
  275.         dd    000FF0FF0h,0F0FF0FF0h,00FFF0FF0h,0FFFF0FF0h
  276.         dd    00000FFF0h,0F000FFF0h,00F00FFF0h,0FF00FFF0h
  277.         dd    000F0FFF0h,0F0F0FFF0h,00FF0FFF0h,0FFF0FFF0h
  278.         dd    0000FFFF0h,0F00FFFF0h,00F0FFFF0h,0FF0FFFF0h
  279.         dd    000FFFFF0h,0F0FFFFF0h,00FFFFFF0h,0FFFFFFF0h
  280.         dd    00000000Fh,0F000000Fh,00F00000Fh,0FF00000Fh
  281.         dd    000F0000Fh,0F0F0000Fh,00FF0000Fh,0FFF0000Fh
  282.         dd    0000F000Fh,0F00F000Fh,00F0F000Fh,0FF0F000Fh
  283.         dd    000FF000Fh,0F0FF000Fh,00FFF000Fh,0FFFF000Fh
  284.         dd    00000F00Fh,0F000F00Fh,00F00F00Fh,0FF00F00Fh
  285.         dd    000F0F00Fh,0F0F0F00Fh,00FF0F00Fh,0FFF0F00Fh
  286.         dd    0000FF00Fh,0F00FF00Fh,00F0FF00Fh,0FF0FF00Fh
  287.         dd    000FFF00Fh,0F0FFF00Fh,00FFFF00Fh,0FFFFF00Fh
  288.         dd    000000F0Fh,0F0000F0Fh,00F000F0Fh,0FF000F0Fh
  289.         dd    000F00F0Fh,0F0F00F0Fh,00FF00F0Fh,0FFF00F0Fh
  290.         dd    0000F0F0Fh,0F00F0F0Fh,00F0F0F0Fh,0FF0F0F0Fh
  291.         dd    000FF0F0Fh,0F0FF0F0Fh,00FFF0F0Fh,0FFFF0F0Fh
  292.         dd    00000FF0Fh,0F000FF0Fh,00F00FF0Fh,0FF00FF0Fh
  293.         dd    000F0FF0Fh,0F0F0FF0Fh,00FF0FF0Fh,0FFF0FF0Fh
  294.         dd    0000FFF0Fh,0F00FFF0Fh,00F0FFF0Fh,0FF0FFF0Fh
  295.         dd    000FFFF0Fh,0F0FFFF0Fh,00FFFFF0Fh,0FFFFFF0Fh
  296.         dd    0000000FFh,0F00000FFh,00F0000FFh,0FF0000FFh
  297.         dd    000F000FFh,0F0F000FFh,00FF000FFh,0FFF000FFh
  298.         dd    0000F00FFh,0F00F00FFh,00F0F00FFh,0FF0F00FFh
  299.         dd    000FF00FFh,0F0FF00FFh,00FFF00FFh,0FFFF00FFh
  300.         dd    00000F0FFh,0F000F0FFh,00F00F0FFh,0FF00F0FFh
  301.         dd    000F0F0FFh,0F0F0F0FFh,00FF0F0FFh,0FFF0F0FFh
  302.         dd    0000FF0FFh,0F00FF0FFh,00F0FF0FFh,0FF0FF0FFh
  303.         dd    000FFF0FFh,0F0FFF0FFh,00FFFF0FFh,0FFFFF0FFh
  304.         dd    000000FFFh,0F0000FFFh,00F000FFFh,0FF000FFFh
  305.         dd    000F00FFFh,0F0F00FFFh,00FF00FFFh,0FFF00FFFh
  306.         dd    0000F0FFFh,0F00F0FFFh,00F0F0FFFh,0FF0F0FFFh
  307.         dd    000FF0FFFh,0F0FF0FFFh,00FFF0FFFh,0FFFF0FFFh
  308.         dd    00000FFFFh,0F000FFFFh,00F00FFFFh,0FF00FFFFh
  309.         dd    000F0FFFFh,0F0F0FFFFh,00FF0FFFFh,0FFF0FFFFh
  310.         dd    0000FFFFFh,0F00FFFFFh,00F0FFFFFh,0FF0FFFFFh
  311.         dd    000FFFFFFh,0F0FFFFFFh,00FFFFFFFh,0FFFFFFFFh
  312.  
  313. ;-----------------------------------------------
  314. ;    漢字コ-ドチェックテ-ブル        
  315. ;-----------------------------------------------
  316. SJIS1?        equ    1
  317. SJIS2?        equ    2
  318. ;            0 1 2 3 4 5 6 7 8 9 A B C D E F
  319. sjis_tbl    db    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0    ;0
  320.         db    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0    ;1
  321.         db    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0    ;2
  322.         db    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0    ;3
  323.         db    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2    ;4
  324.         db    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2    ;5
  325.         db    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2    ;6
  326.         db    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0    ;7
  327.         db    2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3    ;8
  328.         db    3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3    ;9
  329.         db    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2    ;A
  330.         db    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2    ;B
  331.         db    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2    ;C
  332.         db    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2    ;D
  333.         db    3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3    ;E
  334.         db    3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0    ;F
  335. ;---------------------------------------------------------------
  336. DATA        ends
  337. ;===============================================================
  338. BSS        segment
  339.  
  340. font_color    dd    ?
  341. back_color    dd    ?
  342.  
  343. BSS        ends
  344. ;===============================================================
  345.         end
  346.